home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7443 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  59 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help - pointer notation please...
  5. Date: 26 Feb 1996 17:18:28 GMT
  6. Organization: OpenVision
  7. Message-ID: <4gsq14$3uc@spanky.pls.ov.com>
  8. References: <4gjelv$2ek@news.mistral.co.uk>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 2ek@news.mistral.co.uk, mikebarnard@mistral.co.uk (Mike Barnard) writes:
  13. >Hi.
  14. >
  15. >I've read my C book. I've gotten th C FAQ. I've read the file
  16. >"ptrtutor.txt" a tutorial on pointers. But I havn't seen explained the
  17. >following. Can you help?
  18. >
  19. >Sometimes when prototyping a function the function name is pre-fixed
  20. >by an asterisk. Why? What does it mean?
  21. >
  22. >Putting an asterisk before a variable name declares it as a pointer
  23. >variable. Putting one before the variable in use means you want to
  24. >access the data pointed to. Why is there sometimes an asterisk AFTER a
  25. >variable?
  26. >
  27. >All hint's will be of GREAT use. Thanks.
  28. >
  29. >---
  30. >Mic.
  31. >From very windy and now snowy Worthing; England.
  32. >mikebarnard@mistral.co.uk
  33. >
  34. >(I just lost 4 fence panels to the wind here! The cost of
  35. >replacing them could have bought me a new windows compiler!)
  36. >
  37.  
  38. The use of '*' is context dependent.  In variable declarations it always
  39. means pointer (unless it is used in an initializer).  In statements it can
  40. either mean "dereference pointer" or "multiply" depending on how it is used.
  41.  
  42. Consider:
  43.  
  44. int ad = 3 * 4, *a, bd, *b, c;
  45.  
  46. int main()
  47. {
  48.     b = &bd;
  49.     a = &ad;
  50.     *b = 10;
  51.     c = *a * (*b);
  52.     return(c);
  53. }
  54.  
  55. Can you see why c == 120 is true?
  56.  
  57.             Fletcher.Glenn@ov.com
  58.  
  59.